home *** CD-ROM | disk | FTP | other *** search
/ Rover 25 Presentation / Rover25_Presentation_CD.bin / Tool2.cst / 00071_Script_Zeus sound fade < prev    next >
Text File  |  2000-01-31  |  6KB  |  230 lines

  1.  
  2. -- Sound Fade Behavior
  3.  
  4. -- This script is compatible with Director 6 and 7.
  5.  
  6. -- Paste this script into a Behavior (Score) script.
  7.  
  8. -- (Watch out for long line breaks).
  9.  
  10. -- Then drop the Behavior into the script channel.
  11.  
  12. -- Copyright. Bruce A. Epstein. All Rights Reserved.
  13.  
  14. -- Version 1.0, June 18, 1999
  15.  
  16. -- http://www.zeusprod.com/nutshell/fade.html
  17.  
  18.  
  19.  
  20. property pSoundChannel, pBegin, pStart, pEnd, pDuration, pStartTime
  21.  
  22. property pChangePerTick, pTight, pWait
  23.  
  24.  
  25.  
  26. -- Initialization
  27.  
  28. on beginSprite me
  29.  
  30.   -- Record starting time for later calculations
  31.  
  32.   set pStartTime = the ticks
  33.  
  34.   
  35.  
  36.   -- If user didn't specify a starting volume, use the current volume
  37.  
  38.   if pBegin then
  39.  
  40.     set pStart = the volume of sound pSoundChannel
  41.  
  42.   end if
  43.  
  44.   
  45.  
  46.   -- Jump abruptly to the starting volume if necessary
  47.  
  48.   if the volume of sound pSoundChannel <> pStart then
  49.  
  50.     set the volume of sound pSoundChannel = pStart
  51.  
  52.   end if
  53.  
  54.   
  55.  
  56.   -- Calculate how much to change the volume in each tick of time
  57.  
  58.   set pChangePerTick = float(pEnd - pStart)/pDuration  
  59.  
  60. end beginSprite
  61.  
  62.  
  63.  
  64. on endSprite me
  65.  
  66.   -- Set the ending volume even if rounding errors left it at an inexact level
  67.  
  68.   set the volume of sound pSoundChannel = pEnd
  69.  
  70. end endSprite
  71.  
  72.  
  73.  
  74.  
  75.  
  76. on exitFrame me
  77.  
  78.   -- Fade the sound up or down between the starting and ending volumes.
  79.  
  80.   -- There are several possible modes for waiting:
  81.  
  82.   -- If pTight is TRUE, we'll create a tight repeat loop and fade the sound
  83.  
  84.   -- If pTight is FALSE, we'll adjust the volume once per exitFrame event
  85.  
  86.   -- If pWait is TRUE, we'll also wait in the frame until the sound fade completes
  87.  
  88.   -- If pTight and pWait are both FALSE, the sound will fade for the number of
  89.  
  90.   -- frames over which the script is tweened. When leaving the sprite span
  91.  
  92.   -- the ending volume will may be set abruptly in that case.
  93.  
  94.   
  95.  
  96.   if pTight then
  97.  
  98.     -- pTight is TRUE, so we'll create a tight repeat loop and fade the sound
  99.  
  100.     repeat while not done(me)
  101.  
  102.       set elapsed = the ticks - pStartTime
  103.  
  104.       set the volume of sound pSoundChannel = pStart + elapsed * pChangePerTick
  105.  
  106.     end repeat
  107.  
  108.     
  109.  
  110.   else
  111.  
  112.     -- pTight is FALSE, so we'll adjust the volume once per exitFrame event
  113.  
  114.     set elapsed = the ticks - pStartTime
  115.  
  116.     set the volume of sound pSoundChannel = pStart + elapsed * pChangePerTick
  117.  
  118.     
  119.  
  120.     -- If desired, wait in the frame until the final volume is achieved
  121.  
  122.     if pWait and not done (me) then
  123.  
  124.       go the frame
  125.  
  126.     end if
  127.  
  128.   end if
  129.  
  130. end exitFrame
  131.  
  132.  
  133.  
  134.  
  135.  
  136. on done me
  137.  
  138.   -- Check if the sound fade is done.
  139.  
  140.   -- Returns TRUE when we reach or pass the volume of interest
  141.  
  142.   if  (pStart > pEnd) and (the volume of sound pSoundChannel > pEnd) then
  143.  
  144.     return FALSE
  145.  
  146.   else if  (pStart < pEnd) and (the volume of sound pSoundChannel < pEnd) then
  147.  
  148.     return FALSE
  149.  
  150.   else
  151.  
  152.     return TRUE
  153.  
  154.   end if
  155.  
  156. end done
  157.  
  158.  
  159.  
  160. on getBehaviorDescription me
  161.  
  162.   set intro = "-- Sound Fade Behavior by Bruce A. Epstein. Copyright 1999. All rights reserved. " & RETURNs(1)
  163.  
  164.   put "-- See Chapter 15 of Director in a Nutshell and http://www.zeusprod.com/nutshell/fade.html" & RETURNs(2) after INTRO
  165.  
  166.   put "Parameters:"  & RETURNs(1) after INTRO
  167.  
  168.   set desc1 =  "-- pSoundChannel - sound channel to fade (from 1 to 8). Only one channel can be faded at a time." & RETURNs(2)
  169.  
  170.   set desc2 = "-- pBegin - if TRUE, fade begins from current volume, and pStart is ignored." & RETURNs(2)
  171.  
  172.   set desc3 =  "-- pStart - starting volume for fade (0-255). If pBegin is TRUE, this parameter is ignored. " & RETURNs(2)
  173.  
  174.   set desc4 =  "-- pEnd - ending volume for fade (0-255).  Automatically fades up or down, depending on relation to pStart." & RETURNs(2)
  175.  
  176.   set desc5 =  "-- pDuration - number of ticks over which to create fade. Default is 180 ticks (3 seconds)." & RETURNs(2)
  177.  
  178.   set desc6 =  "-- pTight - if TRUE, sound fade is performed in a tight repeat loop, locking out animation and screen updates. If FALSE, sound is faded incrementally each time exitFrame event is sent." & RETURNs(2)
  179.  
  180.   set desc7 =  "-- pWait - if TRUE, wait in the frame until the sound fade completes. If pTight is FALSE and pWait is FALSE, the sound will change over the range of frames over which the script is tween. pWait is irrelevant if pTight is TRUE." & RETURNs(2)
  181.  
  182.   
  183.  
  184.   set desc = intro & desc1 & desc2 & desc3 & desc4 & desc5 & desc6 & desc7
  185.  
  186.   
  187.  
  188.   return desc
  189.  
  190. end
  191.  
  192.  
  193.  
  194. on returns n
  195.  
  196.   set retString = RETURN
  197.  
  198.   repeat with x = 2 to n
  199.  
  200.     put RETURN after retString
  201.  
  202.   end repeat
  203.  
  204.   return retString 
  205.  
  206. end
  207.  
  208.  
  209.  
  210. on getPropertyDescriptionList me
  211.  
  212.   set param1 =  [#default: 1, #format:#integer, #range:[1,2,3,4,5,6,7,8], #comment: "Sound Channel"]
  213.  
  214.   set param2 =  [#default: TRUE, #format:#boolean, #comment: "Start from Current Volume"]
  215.  
  216.   set param3 =  [#default: 0, #format:#integer, #range:[#min:0, #max:255], #comment: "Start Volume"]
  217.  
  218.   set param4 =  [#default: 255, #format:#integer, #range:[#min:0, #max:255], #comment: "End Volume"]
  219.  
  220.   set param5 =  [#default: 180, #format:#integer, #range:[#min:0, #max:600],#comment: "Duration in ticks"]
  221.  
  222.   set param6 =  [#default: FALSE, #format:#boolean, #comment: "Tight Repeat loop"]
  223.  
  224.   set param7 =  [#default: TRUE, #format:#boolean, #comment: "Wait in frame"]
  225.  
  226.   
  227.  
  228.   return [#pSoundChannel:param1, #pBegin:param2, #pstart:param3, #pEnd:param4, #pDuration:param5, #pTight:param6, #pWait:param7]  
  229.  
  230. end getPropertyDescriptionList